Skip to content

Instantly share code, notes, and snippets.

@farid-mkh
Created January 25, 2023 06:27
Show Gist options
  • Select an option

  • Save farid-mkh/d140916b093a3f8505128f008d3b058a to your computer and use it in GitHub Desktop.

Select an option

Save farid-mkh/d140916b093a3f8505128f008d3b058a to your computer and use it in GitHub Desktop.
useful git commands

Github commands

before push and connect to remote

initialize git for a project

git init

see all changes on repo

git log --all --decorate --oneline --graph

see all available new commits

git status

to save changes but not commit to change branch and commit changes later

git stash

stash list

git stash list

makes ready changed files to commit

git add .

or

git add SPECIFIC_FILE

commit changes

git commit -m "title"

adding remove / existing repo for push

git remote add origin REPO_URL

push changes

git push

change last commit title

git commit --amend -m "New commit message"

revert last commit

git update-ref -d HEAD

see all branches

git branch

create new branch

git checkout -b NEWBRANCH

change branch

git checkout branchname

delete branch

git branch -d BRANCHNAME

merge

show merged branches

git branch --merged

show changes in BRANCHNAME

git diff MAIN...BRANCHNAME

fast forward merge : merge directly changes and updates

merge BRANCHNAME to MAIN

git checkout MAIN
git merge BRANCHNAME

3-way merge: for merging branches that are from same source but they from seperately

4- working with remotes

show all remotes

git remote -v

add remote

git remote set-url --add --push origin git://original/repo.git

5- how to load specific commit

git checkout <commit-id>

Add a repo from gitlab to github

git remote add github https://yourLogin@github.com/yourLogin/yourRepoName.git
git push --mirror github
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment