Git Commands
I’m always forgetting basic git commands, so I figured I’d make a list here I can reference. Hopefully it’s a help to you, too!
To clone a remote repo:
-
Navigate to local folder
-
Clone remote repo
Terminal window git clone {URL}
When making changes:
- Make local changes
- Add changes to staging area
Terminal window git add -A - Commit changes to local repo
Terminal window git commit -m "message" - Pull remote repo (to make sure no one has updated remote repo)
Terminal window git pull origin master - Then push it to the remote repo
Terminal window git push origin master
Working with branches:
-
Create a branch
Terminal window git branch [name of branch] -
Checkout branch
Terminal window git checkout [name of branch] -
add, commit change to local branch
Terminal window git add -ATHEN
Terminal window git commit -m "message" -
commit push branch to remote
Terminal window git push -u origin [name of branch](just first time to push it to remote and link the two together)
-
in the future… you can just use
Terminal window git push
To merge…
- Switch to master change
Terminal window git checkout master - Pull from master to make sure we’re up to date
Terminal window git pull origin master - Merge branch
Terminal window git merge [name of branch] - Push to remote
Terminal window git push origin master - Check to see which things have been merged into master
Terminal window git branch --merged
To delete branch
- Check to make sure it’s merged (should show merged branch)
Terminal window git branch --merged - Delete local branch
Terminal window git branch -d [branch name] - Delete remote branch
Terminal window git push origin --delete [name of remote branch] - Check everything
(double check all local and remote branches are deleted)
Terminal window git branch -a