Here is a list of some useful git commands.
Initialize empty Git repository
git init
Stage a file
git add filepath
Stage all files
git add .
Commit file changes
git commit -m "commit message"
Check for staged and unstaged files
git status
Push committed changes to master branch
git push
Push committed changes to a particular branch
git push origin branchname
Force push committed change
git push -f
Create a new branch
git checkout -b branchname
Switch to an existing branch
git checkout branchname
Delete a branch locally
(first ensure that you are not on the branch you intend to delete)
to delete branch only if it has already been pushed and merged with the remote branch
git branch -d localBranchName
delete the branch only if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet
git branch -D localBranchName
Delete a branch remotely
(first ensure that you are not on the branch you intend to delete)
git push origin --delete remoteBranchName
Update current branch with changes from a remote repository
git pull
Clone a repository
git clone <url>
Manage connections to remote repositories
show URLs of remote repositories
git remote -v
create a new connection to a remote repository
git remote add <shortname> <url>
disconnect the remote from the local repository
git remote remove <name>
rename a remote connection
git remote rename <old-name> <new-name>
Fix last commit message
git commit --amend -m "correct commit message"
Top comments (8)
Hello, when you clone a repository, then the command:
Works as spected, becase the remote repository is configured with the master brach by default.
If isn´t the case you would configure it with:
In general: git push -u [name of remote] [name of branch]
at this manner when you are in any configured branch, 'git push' makes a push from the current branch to the remote.
Thanks for share
I also use following command to delete remote branch:
Hmm. This git command actually pushes your branch to a remote branch. I guess you forgot to add --delete .
No. I've added the
:
in front of my remote branch.This feature is available since Git 1.5 version is released :).
Yes.. TIL. Thanks!
Best thing you can do for your git game, is using ZSH that has a built-in git plugin. Check this out :) github.com/ohmyzsh/ohmyzsh/blob/ma...
And my two favorite aliases:
I use these all the time in feature branches
Yh, Nice! 👍🏽