Skip to content

msaaddev/git-commands-workflows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 Cannot retrieve latest commit at this time.

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

git-commands-workflows

The git commands & workflows I use on a daily basis.


Initialization

# paste this in your terminal to change your current working directory to the project directory
cd your_project_path

# initialize git
git init

Commands

⚑️ The repetitive commands that I (and everyone else) use regularly.

# connect the remote GitHub repo with your local project
git remote add origin [github-repo-url]

# see untracked files
git status

# add all untracked files to the staging area
git add .

# commit the tracked files of the staging area
git commit -m "commit-msg"

# push all the changes to the GitHub
git push -u origin master

🎩 Clone a repository in your computer.

# clone a repo
git clone [repo_url]

🌲 The git commands you need to know to work with branches.

# list all branches
git branch

# create a new branch
git branch [branch_name]

# checkout to the new branch
git checkout [branch_name]

# 				OR

# create AND checkout to the new branch
git checkout -b [branch_name]

# pushing the new branch on GitHub
git push origin [branch_name]

# delete a branch
git branch -d [branch_name]

🎯 Keep your GitHub forked repo in sync with the original repository.

# STEP #1: show URLs of remote repositories when listing your current remote connections
git remote -v

# STEP #2: add upstream
git remote add upstream [source-repo-url]

# STEP #3: fetching all the new changes from the main repository
git fetch upstream

# STEP #4: merging the new changes from the original repo to your forked local repo
git merge upstream/master

# STEP #5: pushing the new changes of the forked local repo to the GitHub
git push origin master

Workflows

Open your .zshrc or .bashrc file. It is located in your root directory. Paste the following shellcode there.

# Keep your GitHub forked repo in sync with the original repository with master as the primary branch
function fetchremotems() {
	git fetch upstream &&
	git merge upstream/master &&
	git push origin master
}

# Keep your GitHub forked repo in sync with the original repository with master as the primary branch
function fetchremotemn() {
	git fetch upstream &&
	git merge upstream/master &&
	git push origin master
}

# create new branch and checkout to it
function gcb() {
	git checkout -b "${1}"
}

# checkout to a branch
function gc() {
	git checkout "${1}"
}

# push changes to another branch
function gbp() {
	git push origin "${1}"
}

# add, commit, push changes to github
function gacp() {
	git add . &&
	git commit -m "${1}" &&
	git push
}

πŸ’₯ Fetching changes from the original repo to your forked repo.

cd your_project_path

# do this only once in every forked local repo to add upstream
git remote add upstream [source-repo-url]

# write the following in the terminal – primary branch: master – whenever you need to fetch the changes
fetchremotems

# write the following in the terminal – primary branch: main – whenever you need to fetch the changes
fetchremotemn

🎲 Usage of the rest of the workflows.

# To create a new branch and also to checkout to it
gcb [branch_name]

# To checkout to an existing branch
gc [branch_name]

# To push changes to another branch
gbp [branch_name]

# To add, commit and push changes to the github
gacp "commit-msg"

NOTE I extensively use Emoji-log by Ahmad Awais in my commit msgs. I would highly recommend you to take a look at its workflows.

πŸ‘¨πŸ»β€πŸ’» Contributing

Feel free to add your git workflows in the repository. Just make sure you first read the contributing guidelines before making a PR.

πŸ”‘ License