Skip to content

Instantly share code, notes, and snippets.

@acxgray
Last active October 25, 2021 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acxgray/fc3ebf0156bae736f7898f13fd8ac7d9 to your computer and use it in GitHub Desktop.
Save acxgray/fc3ebf0156bae736f7898f13fd8ac7d9 to your computer and use it in GitHub Desktop.
Git Commands

Make a new branch

git branch <name>

Show branches (* is the active/current branch)

git branch

Check/view the other branch

git checkout <branch name>

Combine target branch with working branch

for example, we want to merge other branch to main branch

git checkout main
git merge <other-branch>

Merge branch from local to remote

git checkout main # switch to main branch
git pull origin main # get the latest changes in main branch
git merge <Branch name to merge> # merge with the update branch
git push origin main # upload the changes to master

Handling a merge conflict.

once you have applied the changes to merge conflict, you can type:

git add .
git merge --continue 

to continue merging after the merge conflict

To cancel merging process

git merge --abort

Rebasing makes it look like you split off from a branch

at a different commit (usually latest)

git rebase master

Rebase Conflict (solve the conflict first) then type:

git rebase --continue

to abort rebase

git rebase --abort

Git Remote - Upload Local to Remote Repository (Github)

cd local git
git checkout master
git remote add origin <github repo url>
git push origin main

Download/Fetch changes in a branch from remote

git pull origin main

Renaming a Git Branch (Local and Remote)

git checkout <old_name> # switch to local branch you want to rename
git branch -m <new_name> # Rename local branch to desired name
git push origin - u <new_name> # Push the new local branch name and reset the upstream
git push origin --delete <old_name> # Delete the old_name remote branch

Download/Clone a repository from github

git clone https://github.com/microsoft/vscode.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment