Git Cheatsheet GitHub
Git Cheatsheet GitHub
ziritrion / git.md
Last active last month
Star
git cheatsheet
git.md
Basic git
1. Make sure your local copy of the selected branch is updated.
git pull
https://gist.github.com/ziritrion/d73ca65bf4d19c79ca842a55853cb962 1/4
12/15/22, 12:09 PM git cheatsheet · GitHub
8. Commit
git commit -m "This is a commit message"
10. Make sure you upload your commits to the remote repo! If your local branch is brand
new, you must add it to the remote repo.
i. New branch
git push -u origin new_branch
12. Merge some branch into your current branch (assuming default behavior of pull is
merge)
git pull branch_that_will_be_merged_into_current_branch
Advanced git
The following are some best practices that may be useful, taken from this blog post
1. While working on a branch, if you need to pull commits from the remote repo to your
local repo, use rebase instead of merge to reduce the amount of commits
git pull --rebase
If you want to make rebasing the default behavior when doing git pull , do so
with git config --global --bool pull.rebase true
2. Before pushing your changes to the remote repo, perform basic houseleeping (squash
related commits together, rewording messages, etc)
git rebase -i @{u}
3. Merge (do not rebase) changes from master/main into your branch, in order to
update the branch with the latest features and solve any compatibility issues and/or
https://gist.github.com/ziritrion/d73ca65bf4d19c79ca842a55853cb962 2/4
12/15/22, 12:09 PM git cheatsheet · GitHub
conflicts
i. git merge main
ii. git pull --merge main
4. Enforce merge commit when merging feature branch into main, even if a merge
commit isn't necessary (check next point for exception), in order to make it easier to
see the where and when of changes. Assuming you're in main:
git merge --no-ff branch_that_will_be_merged_into_main
5. Exception to point 4: if you only need to merge a single commit (typical for stuff such
as bugfixes). Assuming you're in main:
git cherry-pick branch_that_only_has_a_single_commit
Official method
Source
1. Make sure you've got a local commit. You may initialize a local repo with git init on
any project folder and making sure that it has at least one commit, or you may use an
already existing local repo.
2. On a separate folder, run:
This will create a folder with name project.git on the folder you're running the
command.
Remote repo folders use the .git extension as a standard.
This folder is a bare repository. It does not contain a working folder, only the git
files.
3. Move the project.git folder to the final destination. Ideally, a shared folder such as
a networked drive that everyone has access to "locally".
https://gist.github.com/ziritrion/d73ca65bf4d19c79ca842a55853cb962 3/4
12/15/22, 12:09 PM git cheatsheet · GitHub
You may combine steps 2 and 3 by creating the bare repo directly on the final
folder.
4. You should now be able to clone the repo:
5. The original repo that we bare-cloned does not have an origin repo to push to. If you
want to keep using it, set up a remote like this:
Alternative method
Source
1. On remote folder:
mkdir my_repo
cd my_repo
git init --bare
2. On local folder:
cd my_repo
git init
git remote add origin ssh://myserver/my_repo
git add .
git commit -m "Initial commit"
git push -u origin master
https://gist.github.com/ziritrion/d73ca65bf4d19c79ca842a55853cb962 4/4