DEV Community

Chaitanya Asati
Chaitanya Asati

Posted on

Github commands

To list all remote repositories as shortnames connected to your local repository

git remote
Enter fullscreen mode Exit fullscreen mode

To list all remote repositories with their url's connected to your local repository

git remote -v
Enter fullscreen mode Exit fullscreen mode

To connect to a new remote repository

git remote add testtech https://testtech@github.com/testtechcomp/testtech.git

Enter fullscreen mode Exit fullscreen mode

To disconnect remote repository from your local repository

git remote remove testech
Enter fullscreen mode Exit fullscreen mode

To rename remote repository in your local repository

git rename testtech prodtech
Enter fullscreen mode Exit fullscreen mode

To fetch all changes from a remote repository without changing any code in any of branches in your local repository

git fetch testtech
Enter fullscreen mode Exit fullscreen mode

To list all local branches in your local repository

git branch
Enter fullscreen mode Exit fullscreen mode

To list all remote branches in your local repository

git branch -r
git branch -r -v
Enter fullscreen mode Exit fullscreen mode

To see all local branches and remote branches in your local repository

git branch -a
Enter fullscreen mode Exit fullscreen mode

To create a copy of remote branch in your local repository

git fetch testtech
git fetch testtech unit_testing
git checkout testtech/unit_testing
git checkout -b unit_testing_local

Enter fullscreen mode Exit fullscreen mode

To update your local branch with latest changes in remote repository

git fetch testtech <remote_branch_name>
git checkout <local_branch_name>
git merge testtech/<remote_branch_name>
Enter fullscreen mode Exit fullscreen mode

To see latest commit ids, commit messages and tracking remote branch of all local branches

git branch -vv
Enter fullscreen mode Exit fullscreen mode

To publish a local branch to remote branch

git push -u origin dev
Enter fullscreen mode Exit fullscreen mode

To create a copy of remote branch in your local repository and also set tracking branch at same time

git checkout --track testtech/functional_testing
Enter fullscreen mode Exit fullscreen mode

To set tracking branch of your local repository to a branch in remote repository

git branch -u testtech/unit_testing
Enter fullscreen mode Exit fullscreen mode

To delete local branches

git branch -d <branch_name>
Enter fullscreen mode Exit fullscreen mode

To delete remote branches

git push origin --delete <branch_name>
Enter fullscreen mode Exit fullscreen mode

To undo the commits and delete also those commits

git reset --hard HEAD~1
git reset --hard 0ad5a7a6
Enter fullscreen mode Exit fullscreen mode

To undo the commits and don't delete the file changes

git reset --soft HEAD~1
Enter fullscreen mode Exit fullscreen mode

To create a new branch and with state of a particular commit

git checkout -b old-project-state 0ad5a7a6
Enter fullscreen mode Exit fullscreen mode

To create a new branch with history of a particular branch irrespective what is your current branch

git checkout -b <new_branch_name> <branch_from_which_to_copy_history>
Enter fullscreen mode Exit fullscreen mode

To remove files from staging area

git restore --staged <file> 
Enter fullscreen mode Exit fullscreen mode

To undo the changes in a file

git restore <file_name>
Enter fullscreen mode Exit fullscreen mode

To see all commit history of current branch

git log
Enter fullscreen mode Exit fullscreen mode

To merge all changes in a feature branch to current branch

git checkout <branch_name_to_which_we_want_changes>
git merge <feature_branch>
Enter fullscreen mode Exit fullscreen mode

To remove the remote tracking branch info

git branch --unset-upstream
Enter fullscreen mode Exit fullscreen mode

To set the remote tracking branch info

git branch --set-upstream-to=origin/new-branch
Enter fullscreen mode Exit fullscreen mode

Top comments (0)