Pushing Changes to a Remote Repository
- Open Git Bash
- Navigate to your project directory. Since I had already cloned the repository, I already have a local repository at D:\VSCode\python\safefile\safe-file-transfer-system, so I can skip steps 3-4. If you don't have a repository yet, you'll need to create one.
- Initialize a local Git repository: ```
git init
- After successful initialization, a .git folder will appear in your dircetory
- Add files to the Git repository: Use the git add command to stage files. You can add individual files or entire directories. ```
git add
Or add all files
git add . - Commit your changes with a descriptive message: ```
git commit -m "Description of your changes"
- Push your changes to the remote repository: ```
git push
Since I had already cloned the repository and my account is linked, I can simply use: ``` git push
If this is your first time pushing to the remote repository, you need to establish a connection first:
git remote add project-repo https://github.com/username/safe-file-transfer-system.git
Here, 'project-repo' is the name you're giving to your remote repository, followed by the repository URL (make sure to use the HTTPS URL from the Code button, not just the browser address).
To pull updates from collaborators to your local repository:
git pull origin main
Where 'origin' is the remote repository name and 'main' is the branch name.
Creating a New Branch and Pushing to Remote
Before creating a new branch, ensure your staging area is clean. Create the branch first, then add the relevant files to avoid confusion.
- Create a new local branch: ```
git checkout -b feature-branch
'feature-branch' is the name of your new local branch. - Push the local branch to the remote repository: ```
git push --set-upstream origin feature-branch
This will create a corresponding branch on the remote repository.
Working with a Single Master Branch
If you prefer to work with just one branch instead of multiple branches, you can use the master branch:
- When you initialize your local repository with git init, use git branch to see available branches. Typically, you'll have a master branch.
- Add all files to the staging area
- Commit your changes
- Push to the master branch: ```
git push --set-upstream origin master
Switching Between Local Branches
To switch to a specific local branch:
git checkout master
This command will switch you to the master branch and show you which remote branch it's tracking (e.g., origin/master).